package com.mg.game.base;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;

import com.mg.framework.kernel.Actor;
import com.mg.framework.kernel.GameApplication;
import com.mg.framework.kernel.Screen;

public class Logo extends Actor {

	private Paint paint = null;
	private int alpha = 0;

	private long s = 0;
	private long e = 0;
	private boolean f = false;

	public Logo(Screen screen, Bitmap bitmap) {
		super(screen, bitmap);
		this.setX(this.screen.getXCenter() - bitmap.getWidth() / 2);
		this.setY(this.screen.getYCenter() - bitmap.getHeight() / 2);
		this.paint = new Paint();
		this.paint.setAntiAlias(true);
		this.paint.setAlpha(0);
	}

	@Override
	public void gameUpdate() {
		if (!this.f && this.alpha < 255) {
			this.paint.setAlpha(this.alpha += 5);
			if (this.alpha == 255) {
				this.s = System.currentTimeMillis();
				this.f = true;
			}
			return;
		}
		this.e = System.currentTimeMillis();
		if ((this.e - this.s) <= 2000) {
			return;
		}
		if (this.f && this.alpha > 0) {
			this.paint.setAlpha(this.alpha -= 5);
			if (this.alpha == 0) {
				GameApplication.me.toMenuScreen();
			}
			return;
		}
	}

	@Override
	public void screenUpdate(Canvas canvas) {
		this.drawSelf(canvas, paint);
	}
}
